<template>
  <div>
    <van-popup
      v-model:show="show"
      position="top"
      :style="{ height: '35%' }"
      :close-on-click-overlay="false"
    >
      <main>
        <!-- 选择年 -->
        <div class="yesr">
          <div @click="last">&lt;</div>
          <span
            >{{ yesr }}年<span v-show="actived < 10 ? true : false">0</span
            >{{ actived }}月</span
          >
          <div @click="next">&gt;</div>
        </div>

        <section>
          <div>
            <span
              v-for="(item, index) in 12"
              :key="index"
              :class="actived === item ? 'spanBGd' : false"
              @click="spanmouth(item)"
            >
              {{ item }}月
            </span>
          </div>
        </section>

        <footer>
           
        </footer>
      </main>
      <div class="button" @click="button">确定</div>
    </van-popup>
  </div>
</template>

<script>
import { Popup as VanPopup, Icon } from "vant";

export default {
  data() {
    return {
      yesr: 1970, //年
      actived: 1, //月
    };
  },
  props: {
    show: {
      type: String
    }
  },
  mounted() {
    //   设置默认年份
    var date = new Date();
    this.yesr = date.getFullYear();
    this.actived = date.getMonth() + 1;
  },
  methods: {
    //   上一年
    last() {
      this.yesr = this.yesr - 1;
    },
    // 下一年
    next() {
      this.yesr = this.yesr + 1;
    },
    //选择月份
    spanmouth(item) {
      this.actived = item;
    },
    //确定
    button() {
      var Datenum=`${this.yesr}-${this.actived}`
      this.$emit('datebutton',Datenum)
    }
  }
};
</script>

<style scoped>
main > .yesr {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 50px;
  width: 100%;
  background: #ffc02e;
}
section {
  width: 100%;
  height: 150px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 1px solid rgb(207, 205, 205);
}
section > div {
  width: 74%;
  height: 100px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}
section > div > span {
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;

}
.spanBGd {
  background: #ffc02e;
  color: #fff;
  border-radius: 10px;
}
.button {
  width: 80%;
  height: 50px;
  margin: 20px auto;
  line-height: 50px;
  background: linear-gradient(270deg, #fec208 0%, #ffd337 100%);
  outline: none;
  border-radius: 2px;
  text-align: center;
}
</style>